<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<link rel="stylesheet" type="text/css" href="css/paginate.css" />

<table class="rowTable" cellspacing="0">
	<colgroup>
		<col width="100" />
		<col width="200" />
	</colgroup>
	<thead>
		<tr>
			<th>No</th>
			<th>일괄</th>
			<th>고객명</th>
			<th>통신사</th>
			<th>모델명</th>
			<th>협력점</th>
			<th>유치자</th>
			<th>개통일</th>
			<th>개통상태</th>
			<th>구매유형</th>
			<th>요금제</th>
			<th>약정</th>
			<th>최종상담내용</th>
			<th>단말기번호</th>
			<th>기존통신사</th>
			<th>실 판매가</th>
			<th>상부점</th>
			<th>접수일</th>
		</tr>
	</thead>
 	<tbody id="creditList"></tbody>
</table>

<table width="100%">
	<tr>
		<td><div class="paging"><div id="creditListPaging"></div></div></td>
	</tr>
</table>

<script type="text/javascript" src="js/jquery.paginate.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		list(1);
	});

	
	var totalpageCount;//총 페이지 수
	var startPage;//시작 페이지
	function list(page) {
		$.ajax({
			url: 'credit.do',
			type: 'POST',
			dataType:"json",
			data: {
				method: 'list',
				currentPage: page
			},
			indicator: true,
			success: function(jsonData) {
				var display = '';
				$.each(jsonData.values, function(idx, element){
					display += '<tr>';
					display += '<td>' + this.req_seq + '</td>';
					display += '<td>' + this.cust_no + '</td>';
					display += '<td>' + this.cust_nm + '</td>';
					display += '<td>' + this.telno + '</td>';
					display += '<td>' + this.buy_type + '</td>';
					display += '<td>' + this.div_type + '</td>';
					display += '<td>' + this.telco + '</td>';
					display += '<td>' + this.result_cd + '</td>';
					display += '<td>' + this.enter_id + '</td>';
					display += '<td>' + this.audlt_yn + '</td>';
					display += '<td>' + this.lawer_nm + '</td>';
					display += '<td>' + this.lawer_nm + '</td>';
					display += '<td>' + this.lawer_cust_no + '</td>';
					display += '<td>' + this.lawer_telno + '</td>';
					display += '<td>' + this.corp_seq + '</td>';
					display += '<td>' + this.remark + '</td>';
					display += '<td>' + this.enter_dttm + '</td>';
					display += '</tr>';
				});
				$('#creditList').html(display);
				totalpageCount = jsonData.totalCount;//총페이지수 셋팅
				startPage = jsonData.startPage;//시작페이지 셋팅
				paging(totalpageCount, startPage);
			},
			error: function(xhr, status, e){
				alertDialog("데이터를 가져오는 데 실패 하였습니다.");
			}
		});
	}
	
	function paging(totalpageCount, startPage) {
		$("#creditListPaging").paginate({
			count 		: totalpageCount,
			start 		: startPage,
			display     : 10,
			border					: false,
			text_color  			: '#888',
			background_color    	: '#EEE',
			text_hover_color  		: 'black',
			background_hover_color	: '#CFCFCF',
			onChange     			: function(page){
				$.ajax({
					url: 'credit.do',
					type: 'POST',
					data: {
						method: 'list',
						currentPage: page
					},
					indicator: true,
					success:  function() {
						list(page);
					},
					error:function(xhr, status, e){
						alertDialog("데이터를 가져오는 데 실패 하였습니다.");
					}
				});
			}
		});
	}
</script>
